import re
FILTER_PUNTS = re.compile("[^a-z^A-Z]")

filename='sample.txt'
with open(filename,'r') as f:
    text = FILTER_PUNTS.sub(" ", f.read().lower().strip())
    words = text.split()
    #print(words)
    d = {}
    for word in words:
        d[word] = d.get(word, 0) + 1
    d1 = sorted(d.items(),key=lambda i:i[1],reverse=True)
    
    for i in d1:
        print('{}, {}'.format(i[0],i[1]))


# 效率有点低，可以改进一下，试试少做操作，
